package com.amit.hibernate;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

public class Client1 {

	public static void main(String[] args) {
		
		SessionFactory sessionfactory=ChibernateUtil.getfactory();
		Session session=sessionfactory.openSession();
		Transaction tx=session.beginTransaction();
		
		List<String> qualis=new ArrayList<String>();
		qualis.add("M.SC");
		qualis.add("M.C.A");
		qualis.add("M.Tech");
		
		Set<String> exps=new HashSet<String>();
		exps.add("SUN");
		exps.add("IBM");
		exps.add("ORACLE");
		
		Author a1=new Author("amit","amityadav@gmail.com",123,new Date(),qualis,exps);
		session.save(a1);
		
		Author a2=new Author("ajeet","ajeetyadav@gmail.com",67,new Date(),qualis,exps);
		session.save(a2);
		
		
		Book b1=new Book("Master java", 999.9, 1, "JLC");
		session.save(b1);
		
		Book b2=new Book("Master Hib", 999.99, 1, "JLC");
		session.save(b2);
		
		Book b3=new Book("Master java", 999.9, 1, "JLC");
		session.save(b3);
		
		Set<Author> as1=new HashSet<Author>();
		as1.add(a1);
		
		Set<Author> as2=new HashSet<Author>();
		as2.add(a1);
		as2.add(a2);
		
		b1.setAuthors(as1);
		b2.setAuthors(as2);
		b3.setAuthors(as2);
		
		
		
		tx.commit();
		session.close();

	}

}
